<?php

/*
 * 用户权限控制
 */

namespace Model;

class Log
{
	public function orderOperation($pid,$action,$sql)
	{
		$data = array();
		$data['pid'] = $pid;
		$data['uid'] = getIdenty();
		$data['action'] = $action;
		$data['sql'] = $sql;
		$data['time'] = time();

		M('order_log')->add($data);

		return true;
	}

	public function productOperation($table,$pid,$action,$sql)
	{
		$data = array();
		$data['table'] = $table;
		$data['pid'] = $pid;
		$data['uid'] = getIdenty();
		$data['action'] = $action;
		$data['sql'] = $sql;
		$data['time'] = time();

		M('product_log')->add($data);

		return true;
	}

	public function libraryOperation($table,$pid,$action,$sql)
	{
		$data = array();
		$data['table'] = $table;
		$data['pid'] = $pid;
		$data['uid'] = getIdenty();
		$data['action'] = $action;
		$data['sql'] = $sql;
		$data['time'] = time();

		M('library_log')->add($data);

		return true;
	}

	public function pinganOperation($pid,$action,$sql)
	{
		$data = array();
		$data['pid'] = $pid;
		$data['uid'] = getIdenty();
		$data['action'] = $action;
		$data['sql'] = $sql;
		$data['time'] = time();

		M('pingan_log')->add($data);

		return true;
	}

	public function pinfoOperation($table,$pid,$action,$sql)
	{
		$data = array();
		$data['table'] = $table;
		$data['pid'] = $pid;
		$data['uid'] = getIdenty();
		$data['action'] = $action;
		$data['sql'] = $sql;
		$data['time'] = time();

		M('pinfo_log')->add($data);

		return true;
	}
	public function passportOperation($pid,$action,$sql)
	{
		$data = array();
		$data['pid'] = $pid;
		$data['uid'] = getIdenty();
		$data['action'] = $action;
		$data['sql'] = $sql;
		$data['time'] = time();

		M('user_passport_log')->add($data);

		return true;
	}

	/**
	 * [webconfOperation description]
	 * @return [type] [description]
	 */
	public function webconfOperation($sql)
	{
		$data               = array();

		$data['sql']        = $sql;
		$data['userName']   = M('permission_user')->where(array('id'=>getIdenty()))->getField('userName');

		M3('web_conf_log')->add($data);
		return true;
	}
	/**
	 * [webproductOperation description]
	 * @param  [type] $productID [description]
	 * @param  [type] $sql       [description]
	 * @return [type]            [description]
	 */
	public function webproductOperation($productID,$sql)
	{
		$data              = array();

		$data['productID'] = $productID;
		$data['sql']       = $sql;
		$data['userName']  = M('permission_user')->where(array('id'=>getIdenty()))->getField('userName');

		M3('product_log')->add($data);

		return true;
	}

	/**
	 * [webcouponsOperation description]
	 * @param  [type] $couponsID [description]
	 * @param  [type] $sql       [description]
	 * @return [type]            [description]
	 */
	public function webcouponsOperation($couponsID,$sql)
	{
		$data              = array();

		$data['couponsID'] = $couponsID;
		$data['sql']       = $sql;
		$data['userName']  = M('permission_user')->where(array('id'=>getIdenty()))->getField('userName');

		M3('pack_coupons_log')->add($data);

		return true;
	}

	/**
	 * [webUploadfile description]
	 * @param  [type] $uploadFileID [description]
	 * @param  [type] $sql          [description]
	 * @return [type]               [description]
	 */
	public function webUploadfileOperation($uploadFileID,$sql)
	{
		$data              = array();

		$data['uploadfileID'] = $uploadFileID;
		$data['sql']          = $sql;
		$data['userName']     = M('permission_user')->where(array('id'=>getIdenty()))->getField('userName');

		M3('web_uploadfile_log')->add($data);

		return true;
	}

	//考勤单据错误记录
	public function formErrorLog($postParam, $errorInfo){
		$data['postParam'] = json_encode($postParam);
		$data['errorInfo'] = $errorInfo;
		$data['time'] = time();

		$result = M('form_error_log')->add($data);

		if($result !== false){return true;}else{return false;}
	}
}
